<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>哈希函数</title>
</head>
<body>

<script>
  function hashFunc(str, size) {
    let hashCode = 0;

    for (let i = 0; i < str.length; i++) {
      hashCode = 37 * hashCode + str.charCodeAt(i)
    }

    return hashCode % size
  }

  alert(hashFunc("aaa", 17))
  alert(hashFunc("bbb", 17))
  alert(hashFunc("ccc", 17))
  alert(hashFunc("ddd", 17))
</script>

</body>
</html>